<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>测试窗口size</title>
<style>
body,div{
	word-break: break-word;
}

div{
	margin:50px;
	padding:50px;
}
</style>
</head>

<body style="background-color: green">
	<div id="show" style="height: 1000px; background: red"></div>
	
	<div id="yellow" style="height: 1000px; background: yellow"></div>
</body>
<script>
	function appendSize(el) {
		el.innerHTML = 'offsetHeight:' + el.offsetHeight + ';offsetWidth:'
				+ el.offsetWidth + ';clientHeight:' + el.clientHeight
				+ ';clientWidth:' + el.clientWidth
				+ ';scrollHeight:' + el.scrollHeight
				+ ';scrollWidth:' + el.scrollWidth
				
				+ el.innerHTML;
	}

	window.onload = function() {

		appendSize(document.body);

		let show = document.getElementById("show");
		appendSize(show);
	}
	
	console.log("========promise==========");
	console.dir(Promise);
	
	//var p = new Promise();
	//console.log(p);
	
	console.dir(console);
	
	function mysolve(){
		console.log("this is the result");
	}
	
	var p = new Promise(function(resolve,reject){
		
	});
	
	
	var url = 'https://hq.tigerbrokers.com/fundamental/finance_calendar/getType/2017-02-26/2017-06-10';
	var result;
	
	
	var xhr = new XMLHttpRequest();
	xhr.open('get',url,true);
	xhr.send();
	
	xhr.onreadystatechange = function(){
		if(xhr.readyStatus == 4 || xhr.status == 200){
			result = xhr.response;
			console.log("result:");
			console.log(result);
			
			var xhr2 = new XMLHttpRequest();
			xhr2.open('get',url+"?r=1",true);
			xhr2.send();
			
			xhr2.onreadystatechange = function(){
				if(xhr2.readyStatus == 4 || xhr2.status == 200){
					let result2 = xhr2.response;
					console.log("result2:");
					console.log(result2);
				}
			}
		}
	}
	
	
	function want() {
	    console.log('这是你想要执行的代码');
	}

	function fn() {
	    console.log('这里表示执行了一大堆各种代码');

	    // 返回Promise对象
	    return new Promise(function(resolve, reject) {
	        if (typeof want == 'function') {
	            resolve(want);
	        } else {
	            reject('TypeError: '+ want +'不是一个函数')
	        }
	    })
	}

	/* fn(want).then(function(want) {
	    want();
	})

	fn('1234').catch(function(err) {
	    console.log(err);
	}) */
	
	
	fn().then(function(){
		console.log("anything");
	});
	
	
	function fn(num) {
	    return new Promise(function(resolve, reject) {
	        if (typeof num == 'number') {
	            resolve();
	        } else {
	            reject();
	        }
	    }).then(function() {
	        console.log('参数是一个number值');
	    }, function() {
	        console.log('参数不是一个number值');
	    })
	}

	fn('hahha');
	fn(1234);
	
	function isNumberBiggerThan6(num){
		
		return new Promise(function(resolve,reject){
			if(num && num > 6){
				resolve();
			}else{
				reject();
			}
		}).then(function(){
			console.log("bigger than 6");
		},function(){
			console.log("smaller than 6");
		});

	}
	
	isNumberBiggerThan6(5);
	isNumberBiggerThan6(7);
	
</script>
</html>